/**
 * 版权所有：福建邮科电信业务部厦门研发中心 
 *====================================================
 * 文件名称: MyStruts1ActionServlet.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    Jun 13, 2012			詹保山(softzbs@126.com)(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 * 
 */
package com.devframe.web.struts1;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.config.ActionConfig;

/**
 * <pre>
 * &lt;b&gt;&lt;font color=&quot;blue&quot;&gt;MyStruts1ActionServlet&lt;/font&gt;&lt;/b&gt;
 * </pre>
 * 
 * <pre>
 * &lt;b&gt; --描述说明--&lt;/b&gt;
 * </pre>
 * <pre></pre>
 * <pre>
 * &lt;b&gt;--样例--&lt;/b&gt;
 *   MyStruts1ActionServlet obj = new MyStruts1ActionServlet();
 *   obj.method();
 * </pre>
 */
public class MyStruts1ActionServlet extends ActionServlet {
	private static final Logger LOG = Logger.getLogger(MyStruts1ActionServlet.class);
	public static final String INCLUDE_PATH_INFO = "javax.servlet.include.path_info";
	public static final String INCLUDE_SERVLET_PATH = "javax.servlet.include.servlet_path";

	protected String processPath(HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		String path;
		// Set per request the original path for postback forms
		if (request.getAttribute(Globals.ORIGINAL_URI_KEY) == null) {
			request.setAttribute(Globals.ORIGINAL_URI_KEY, request
					.getServletPath());
		}

		// For prefix matching, match on the path info (if any)
		path = (String) request.getAttribute(INCLUDE_PATH_INFO);

		if (path == null) {
			path = request.getPathInfo();
		}

		if ((path != null) && (path.length() > 0)) {
			return (path);
		}

		// For extension matching, strip the module prefix and extension
		path = (String) request.getAttribute(INCLUDE_SERVLET_PATH);

		if (path == null) {
			path = request.getServletPath();
		}
		String prefix = super.getModuleConfig(request).getPrefix();

		if (!path.startsWith(prefix)) {
			String msg = getInternal().getMessage("processPath");

			log.error(msg + " " + request.getRequestURI());
			response.sendError(HttpServletResponse.SC_BAD_REQUEST, msg);

			return null;
		}

		path = path.substring(prefix.length());

		int slash = path.lastIndexOf("/");
		int period = path.lastIndexOf(".");

		if ((period >= 0) && (period > slash)) {
			path = path.substring(0, period);
		}
		return (path);
	}

	protected void process(HttpServletRequest request,
			HttpServletResponse response) throws IOException, ServletException {
		String uri=request.getRequestURI();
		if(!uri.contains("!")){// 包含method或 不包含！的字符串
			String path = this.processPath(request, response);
			ActionConfig actionConfig = super.getModuleConfig(request).findActionConfig(path);
			if (actionConfig != null) {
				super.process(request, response);
			}else{
				if(LOG.isDebugEnabled()){
					LOG.debug("在Struts1中没找到配置："+path);
				}
			}
		}
		

	}

}
